/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.lcfgly.Dao;

import com.lcfgly.Database.UserConunt;
import com.lcfgly.DatabaseFactory.DataFactoryInterface;
import com.lcfgly.Interface.GetCacheMark;
import com.lcfgly.Interface.UpdateCacheMark;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

/**
 * 用户信息附加表
 * @author lcfgly
 */
@Repository
public class UserconuntImpl implements Serializable{

    private final String table="user_conunt";
    private final String sqlheader="SELECT uid,address,email,tel,phone,cssstyle,cityaddress,qq,cityid,ipcode,lat,lng FROM user_conunt ";
    
    @Autowired
        @Qualifier("databaseshoprice")
    private DataFactoryInterface dataFactory;
    /**
     * 更新用户信息
     * @param arg0
     * @param userid
     * @return
     * @throws SQLException 
     */
    @UpdateCacheMark(value={"userbyid_${1}","shopuserinferSimplebyid_${1}","shopuserbyid_${1}","shopuserinferbyid_${1}"})
    public int update(UserConunt arg0,int userid) throws SQLException {
        return dataFactory.update(table,arg0, "uid=?", userid);
    }
    
    /**
     * 按照ID查找Userinfer
     * @param id
     * @return
     * @throws SQLException 
     */
    @GetCacheMark("shopuserinferbyid_${0}")
    public UserConunt findByUid(int id) throws SQLException{
        String sql=sqlheader+" WHERE uid=?";
        return dataFactory.one(UserConunt.class,sql, id);
    }
    
    /**
     * 查找简单的用户信息
     * @param id
     * @return
     * @throws SQLException 
     */
    @GetCacheMark("shopuserinferSimplebyid_${0}")
    public Map findSimpleById(int id)throws SQLException{
        String sql="SELECT phone,cssstyle,tel,email FROM "+table+" WHERE uid = ?";
        return dataFactory.oneWithOutObject(sql, id);
    }
    
    /**
     * 插入数据
     * @param arg
     * @return
     * @throws SQLException 
     */
    public int insert(UserConunt arg)throws SQLException{
        return dataFactory.insert(arg, table);
    }
    
}
